package BinarySearch;



public class BinarySearch2 {
    public static void main(String[] args) {
    testBinarySearch2();
    }
    public static int binarySearch2(int[] arr, int target) {
        int i = 0, j = arr.length;
        while (i < j) {
            int m = (i + j) >>>1;
            if(arr[m] < target) {
                i = m + 1;
            }
            else if(target < arr[m]) {
                j = m;
            }
            else if (target == arr[m])
             {
                return m;
            }
        }
        return 1;
    }
    public static void testBinarySearch2(){
        int[] arr = {1,10,13,21,25,32,37,42,49,60};
        System.out.println("数组下标:"+binarySearch2(arr,37));
    }
}
